package net.fdukedom.epicurus.presentation.actions;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Base class for all actions. Derive it when creating new action. Override doExecute
 * method to add new functionallity.
 *
 * @author Dmitry Y. Kochelaev
 */
public abstract class AbstractAction<F extends ActionForm> extends Action {

    @Override
    @SuppressWarnings({"unchecked"})
    public final ActionForward execute(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response) {
        return doExecute(mapping, (F) form, request, response);
    }

    /**
     * Executes main part of action.
     *
     * @param mapping action mappings
     * @param form filled form
     * @param request user request
     * @param response server response
     *
     * @return redirect to next page
     */
    protected abstract ActionForward doExecute(ActionMapping mapping, F form,
            HttpServletRequest request, HttpServletResponse response);
}
